package com.linxiao.payment.core.constants;

/**
 * 支付code
 * @author zhoudong
 */
public enum IfCodeEnum {
    /**
     * 支付宝官方支付
     */
    ALIPAY(0,"alipay","支付宝官方支付"),
    /**
     * 微信官方支付
     */
    WXPAY(1,"wxpay","微信官方支付"),
    /**
     * 云闪付开放平台
     */
    YSFPAY(2,"ysfpay","云闪付开放平台"),
    /**
     * Paypal 支付
     */
    PPPAY(3,"pppay","Paypal 支付"),
    /**
     * 大于等于0，小于20
     */
    UPOPPAY(4,"UPOPPAY","银联"),
    /**
     * 微信转账
     */
    WXPAY_TRANSFER(20,"wxpay_transfer","微信转账"),
    /**
     * 支付宝转账
     */
    ALIPAY_TRANSFER(21,"wxpay_transfer","支付宝转账"),
    ;

    private final int code;
    private final String insCode;
    private final String message;

    IfCodeEnum(int code, String insCode, String message) {
        this.code = code;
        this.insCode = insCode;
        this.message = message;
    }

    /**
     * 通过代码获取枚举项
     * @param code
     * @return
     */
    public static IfCodeEnum getByCode(int code) {
        if (code == -1) {
            return null;
        }

        for (IfCodeEnum le : IfCodeEnum.values()) {
            if (le.getCode() == code) {
                return le;
            }
        }

        return null;
    }
    /**
     * 通过描述获取枚举项
     * @param message
     * @return
     */
    public static IfCodeEnum getByMessage(String message) {
        if (message == null) {
            return null;
        }

        for (IfCodeEnum le : IfCodeEnum.values()) {
            if (le.getMessage().equals(message)) {
                return le;
            }
        }

        return null;
    }

    /**
     * 通过代码获取枚举项
     * @param insCode
     * @return
     */
    public static IfCodeEnum getByInsCode(String insCode) {
        if (insCode == null) {
            return null;
        }

        for (IfCodeEnum le : IfCodeEnum.values()) {
            if (le.getInsCode().equals(insCode)) {
                return le;
            }
        }

        return null;
    }


    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public String getInsCode() {
        return insCode;
    }
}
